package com.boot.main.controller;

import com.boot.main.entity.BcomArticle;
import com.boot.main.entity.BcomCategory;
import com.boot.main.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v1/api")
@Api(tags = "博客文章管理")
public class ArticleController {
    @Resource
    private IArticleService articleService;

    @RequestMapping(value="/articles", method = RequestMethod.GET)
    @ApiOperation(value="获取文章列表")
    public Object getArticles(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("title") String title, @RequestParam("cid") Long cid){
        return articleService.getArticles(page, limit, title, cid);
    }

    @RequestMapping(value="/blog/articles", method = RequestMethod.GET)
    @ApiOperation(value="获取文章列表")
    public Object getBlogArticles(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("title") String title, @RequestParam("cid") Long cid, @RequestParam("tag") String tag){
        return articleService.getBlogArticles(page, limit, title, cid, tag);
    }

    @RequestMapping(value="/blog/article/{id}", method = RequestMethod.GET)
    @ApiOperation(value="获取文章详情")
    public Object getArticleById(@PathVariable Long id){
        return articleService.getArticleById(id);
    }

    @RequestMapping(value="/tags", method = RequestMethod.GET)
    @ApiOperation(value="获取文章标签")
    public Object getTags(){
        return articleService.getTags();
    }

    @RequestMapping(value="/article", method = RequestMethod.POST)
    @ApiOperation(value="新增文章")
    public Object saveArticle(@RequestBody BcomArticle article){
        return articleService.saveArticle(article);
    }

    @RequestMapping(value="/article/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="修改文章")
    public Object updateArticle(@RequestBody BcomArticle article){
        return articleService.updateArticle(article);
    }

    @RequestMapping(value="/article/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除文章")
    public Object deleteArticle(@PathVariable Long id){
        return articleService.deleteArticle(id);
    }
}
